"""
__author__ = 'berlinyoung'
@File   :member_charge.py
@Date   :2022/6/7 22:13
-*- coding: utf-8 -*-
"""

# https://developer.work.weixin.qq.com/assistant/tool 开发者调试
import requests
from weixin_api.step4.src.base import Base

class MemberCharge(Base):

    userid = "zhangsan"
    alias = "jackzhang"
    mobile = "+86 13800000000"

    def add(self):
        url = f"https://qyapi.weixin.qq.com/cgi-bin/user/create?access_token={self.token}"
        data = {
            "userid":f"{self.userid}",
            "name":"张三",
            "alias":f"{self.alias}",
            "mobile":f"{self.mobile}",
            "department":[1]
            # "department": [1, 2],
            # "order":[10,40],
            # "position": "产品经理",
            # "gender": "1",
            # "email": "zhangsan@gzdev.com",
            # "is_leader_in_dept": [1, 0],
            # "direct_leader":["lisi","wangwu"],
            # "enable":1,
            # "avatar_mediaid": "2-G6nrLmr5EC3MNb_-zL1dDdzkd0p7cNliYu9V5w7o8K0",
            # "telephone": "020-123456",
            # "address": "广州市海珠区新港中路",
        }
        # json 代表把数据转为json进行发送
        # data --> 不是json
        r = requests.post(url,json=data)
        return r.json()

    def delete(self):
        url = f"https://qyapi.weixin.qq.com/cgi-bin/user/delete?access_token={self.token}&userid={self.userid}"
        r = requests.get(url)
        return r.json()

    def update(self):
        url = f"https://qyapi.weixin.qq.com/cgi-bin/user/update?access_token={self.token}"
        data = {
            "userid":f"{self.userid}",  #区别必填参数和选填参数
            "name":"李四",
            "alias":f"{self.alias}",
            "mobile":f"{self.mobile}",
            "department":[1]
        }
        # json 代表把数据转为json进行发送
        # data --> 不是json
        r = requests.post(url,json=data)
        return r.json()

    def find(self):
        url = f"https://qyapi.weixin.qq.com/cgi-bin/user/get?access_token={self.token}&userid={self.userid}"
        r = requests.get(url)
        return r.json()
